//
//  main.c
//  赋值运算符
//
//  Created by ws on 2017/7/13.
//  Copyright © 2017年 王松. All rights reserved.
//

#include <stdio.h>

/**
 赋值运算符: = 
 复合赋值运算符: +=, -=, /=, %=
 */
/**
 赋值运算符
 赋值运算符:把等号右边的数值放到左边的变量中,同时它作为一个变量表达式本身有值的,它的值就是右边的数
 赋值运算的结合方向:从右往左的
 算术运算符的优先级 高度 赋值运算符的优先级
 */
void test2(){
    int a;
    a = 10;
    printf("a = %d \n",a );
    printf(" %d\n",a = 10);
    int b, c;
    b = c = 2;
    b  = a + c;
    printf("%d",c);
}
/**
 所有赋值运算符的优先级小于算术运算符的优先级
 赋值运算符是所有运算符中除了逗号运算符优先级最低的
 */
void test3(){
    int a = 2;
    a += 10; //等价于 a = a + 10
    printf("a = %d \n",a );
    a -= 8; //等价于 a = a - 8
    printf("a = %d \n",a );
    a *= 2; //等价于 a = a * 2
    printf("a = %d \n",a );
    a /= 4; //等价于 a = a / 4
    printf("a = %d \n",a );
    a %= 2; //等价于 a = a % 2
    printf("a = %d \n",a );
}

int main(int argc, const char * argv[]) {
    int a = 4;
    a *= 2 + 3; //等价于 a = a * (2 + 3)
    printf("a = %d \n",a );
 
  
    return 0;
}
